<?php
session_start();

require_once('../configs/common.php'); 	 
require_once(CONFIGS_DIR."db_connect.php");
require_once(MODELS_DIR.'MyAccount.class.php');
require_once(MODELS_DIR.'Auth.class.php');

if ($_POST['action']=="recovery_pass")
{
	 $request_data=safe_var_Array(json_decode($_POST['data']), true);
	 $response=array();
	 if (!MyAccount::isEmailRegister($request_data['email']))
	 {
		 $response['is_email_register']='no';
		 header('Content-Type: application/json');
		 echo json_encode($response);
	 }
	 else
	 {
		 MyAccount::sendPasswordLink($request_data['email']);
		 $response['is_sent_email']='yes';
		 header('Content-Type: application/json');
		 echo json_encode($response);		 
	 }	 
}

if ($_POST['action']=="new_password")
{
	 $response=array();
	 $request_data=safe_var_Array(json_decode($_POST['data']), true);
	 $new_password_hash=MyAccount::updatePassword($_SESSION['user_id'], $request_data['new_password']);
	 Auth::login($_SESSION['email'], $new_password_hash);
	 $response['is_logged']=true;
	 header('Content-Type: application/json');
	 echo json_encode($response);
}